/*
 * @Descripttion: 
 * @Author: zhaozheng
 * @Version: 0.0.1
 * @Date: 2022-09-28 16:54:15
 * @LastEditors: zhaozheng
 * @LastEditTime: 2025-01-02 10:25:04
 */
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import { resolve } from 'path'
// 引入⬇️
import postCssPxToRem from 'postcss-pxtorem'
import autoprefixer from 'autoprefixer'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite';
import { VantResolver } from '@vant/auto-import-resolver';
// https://vitejs.dev/config/
export default defineConfig({
  base: './',
  plugins: [
    vue({
      reactivityTransform: true, // 开启reactivity转换 可以使用$ref
    }),
    // https://github.com/antfu/unplugin-auto-import
    AutoImport({
      imports: ['vue','vue-router'],
      resolvers: [VantResolver()],
    }),
    Components({
      resolvers: [VantResolver()],
    }),
  ],
  resolve: {
    alias: {
      '@': resolve(__dirname, 'src'),
      '@api': resolve(__dirname, 'src/api'),
      '@views': resolve(__dirname, 'src/views'),
      '@utils': resolve(__dirname, 'src/utils'),
      '@comp': resolve(__dirname, 'src/components'),
      '@assets': resolve(__dirname, 'src/assets'),
    }
  },
  define: {
    // enable hydration mismatch details in production build
    __VUE_PROD_HYDRATION_MISMATCH_DETAILS__: 'true'
  },
  envPrefix: "VUE_APP_", // 环境变量前缀
  css: {
    preprocessorOptions: {
      scss: {
        additionalData: `@use "@/common/scss/_var.scss";@use "@/common/scss/_mixin.scss";@use "@/common/scss/_border.scss";`
      }
    },
    postcss: { // ⚠️关键代码
      plugins: [
        postCssPxToRem({ // 自适应，px>rem转换
           // rootValue: 75, // 1rem的大小
           rootValue({ file }) {
            return file.indexOf('vant')!== -1 ? 37.5 : 75;
          },
          propList: ['*'], // 需要转换的属性，这里选择全部都进行转换
          selectorBlackList: ["html"],
          minPixelValue: 1.5,
          mediaQuery: false,
          exclude: "common"
        }),
        autoprefixer({ // 自动添加前缀
          overrideBrowserslist: [
            "Android 4.1",
            "iOS 7.1",
            "Chrome > 31",
            "ff > 31",
            "ie >= 8"
            //'last 2 versions', // 所有主流浏览器最近2个版本
          ],
          grid: true
        })
      ]
    },
  },
  server:{
    host: '0.0.0.0',
  }
})
